* Table C4: Summary statistics on applicants' ROLs: Applicants' residence

********************************************************************************
************************** Prepare data ****************************************
********************************************************************************

clear all
use id rank mp mp1 pref_for_location pref_for_uni pref_for_faculty pref_for_field pref_for_major using "${data_rols}", clear

merge 1:1 id using "${data_students}", keepusing(funded_only unfunded_only disadv budapest county_town town village)

label variable mp "Same study program consecutively (anywhere on ROL)"
label variable mp1 "Same study program consecutively on the top of the ROL"

lab var funded_only "State-funded contract exclusively"
lab var unfunded_only "Self-funded contract exclusively"

gen state_funded_and_self_funded = 1 - funded_only - unfunded_only
lab var state_funded_and_self_funded "State- and self-funded contracts"

********************************************************************************
************************** Prepare table ***************************************
********************************************************************************

cap file close sumstat
file open sumstat using "${tableC4}", write replace
file write sumstat "\begin{tabular}{l S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker] S[table-number-alignment = center-decimal-marker]} \\ \hline\hline" _n
file write sumstat " & \multicolumn{1}{c}{{\parbox{2.1cm}{\centering All applicants (\%)}}} & \multicolumn{1}{c}{Capital (\%)} & \multicolumn{1}{c}{County town (\%)} & \multicolumn{1}{c}{Town (\%)} & \multicolumn{1}{c}{Village (\%)} \\ " _n
file write sumstat " & \multicolumn{1}{c}{(1)} & \multicolumn{1}{c}{(2)} & \multicolumn{1}{c}{(3)} & \multicolumn{1}{c}{(4)} & \multicolumn{1}{c}{(5)} \\ \hline" _n

file write sumstat " \multicolumn{6}{l}{A. {\it Preference for funding}} \\ " _n
local vars funded_only unfunded_only state_funded_and_self_funded mp mp1
foreach var of varlist `vars' {
	local lab_var: variable label `var'
	quietly: sum `var'
	local stat_mean: 	display %4.1f r(mean)*100
	
	quietly: sum `var' if budapest == 1
	local stat_mean1: display %4.1f r(mean)*100
	
	quietly: sum `var' if county_town == 1
	local stat_mean2: display %4.1f r(mean)*100
	
	quietly: sum `var' if town == 1
	local stat_mean3: display %4.1f r(mean)*100
	
	quietly: sum `var' if village == 1
	local stat_mean4: display %4.1f r(mean)*100
	
	file write sumstat " `lab_var' & `stat_mean' & `stat_mean1' & `stat_mean2' & `stat_mean3' & `stat_mean4' \\ " _n
}

file write sumstat " \multicolumn{6}{c}{} \\ " _n
file write sumstat " \multicolumn{5}{l}{B. {\it Preference for study characteristics}} \\ " _n

local vars pref_for_location pref_for_uni pref_for_faculty pref_for_field pref_for_major
foreach var of varlist `vars' {
	local lab_var: variable label `var'
	quietly: sum `var'
	local stat_mean: 	display %4.1f r(mean)*100
	
	quietly: sum `var' if budapest == 1
	local stat_mean1: display %4.1f r(mean)*100
	
	quietly: sum `var' if county_town == 1
	local stat_mean2: display %4.1f r(mean)*100
	
	quietly: sum `var' if town == 1
	local stat_mean3: display %4.1f r(mean)*100
	
	quietly: sum `var' if village == 1
	local stat_mean4: display %4.1f r(mean)*100
	
	file write sumstat " `lab_var' & `stat_mean' & `stat_mean1' & `stat_mean2' & `stat_mean3' & `stat_mean4' \\ " _n
}

	qui: count
	local count_total: display %12.0fc r(N)
	qui: count if budapest == 1
	local count_total1: display %12.0fc r(N)
	qui: count if county_town == 1
	local count_total2: display %12.0fc r(N)
	qui: count if town == 1
	local count_total3: display %12.0fc r(N)
	qui: count if village == 1
	local count_total4: display %12.0fc r(N)
	
	file write sumstat "\hline \# of applicants & \multicolumn{1}{c}{`count_total'} & \multicolumn{1}{c}{`count_total1'} & \multicolumn{1}{c}{`count_total2'} & \multicolumn{1}{c}{`count_total3'} & \multicolumn{1}{c}{`count_total4'} \\ " _n

file write sumstat "\hline\hline \multicolumn{6}{p{21cm}}{{\it Notes}: The table reports summary statistics on applicants' ROL. Panel A focuses on preference for funding. Specifically, Panel A shows shows the share of applicants who rank state-funded (self-funded) contracts exclusively, the share of students who rank state-funded and self-funded contracts as well, and the share of applicants who rank the same study program with state-funding and self-funding consecutively anywhere on the ROL, and who rank the same study program with state-funding and self-funding consecutively on the top of the ROL. Panel B focuses on preference for program characteristics. Specifically, Panel B shows the share of applicants who rank exclusively contracts that are in the same settlement (single program location), at a single university (single university), and at a single faculty of a university (single university), and the share of applicants who rank exclusively contracts in a single field of study, and in a single major. Column (1) presents these shares for all applicants, and columns (2)--(5) report these shares for applicants residing in the capital, county towns, towns, and villages, respectively.}"
file write sumstat "\end{tabular}" _n
file close sumstat


